package xinya.com.db;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import java.util.List;
import xinya.com.baselibrary.bean.program.SceneBean.PositionBeanConverter;

import xinya.com.baselibrary.bean.program.SceneBean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "SCENE_BEAN".
*/
public class SceneBeanDao extends AbstractDao<SceneBean, Long> {

    public static final String TABLENAME = "SCENE_BEAN";

    /**
     * Properties of entity SceneBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Background = new Property(0, String.class, "background", false, "BACKGROUND");
        public final static Property Created_at = new Property(1, String.class, "created_at", false, "CREATED_AT");
        public final static Property Duration = new Property(2, String.class, "duration", false, "DURATION");
        public final static Property Id = new Property(3, long.class, "id", true, "_id");
        public final static Property Name = new Property(4, String.class, "name", false, "NAME");
        public final static Property Serial = new Property(5, int.class, "serial", false, "SERIAL");
        public final static Property Updated_at = new Property(6, String.class, "updated_at", false, "UPDATED_AT");
        public final static Property DownloadComplete = new Property(7, boolean.class, "downloadComplete", false, "DOWNLOAD_COMPLETE");
        public final static Property Width = new Property(8, float.class, "width", false, "WIDTH");
        public final static Property Height = new Property(9, float.class, "height", false, "HEIGHT");
        public final static Property Screen01 = new Property(10, int.class, "screen01", false, "SCREEN01");
        public final static Property Screen02 = new Property(11, int.class, "screen02", false, "SCREEN02");
        public final static Property PositionBeans = new Property(12, String.class, "positionBeans", false, "POSITION_BEANS");
    }

    private final PositionBeanConverter positionBeansConverter = new PositionBeanConverter();

    public SceneBeanDao(DaoConfig config) {
        super(config);
    }
    
    public SceneBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"SCENE_BEAN\" (" + //
                "\"BACKGROUND\" TEXT," + // 0: background
                "\"CREATED_AT\" TEXT," + // 1: created_at
                "\"DURATION\" TEXT," + // 2: duration
                "\"_id\" INTEGER PRIMARY KEY NOT NULL ," + // 3: id
                "\"NAME\" TEXT," + // 4: name
                "\"SERIAL\" INTEGER NOT NULL ," + // 5: serial
                "\"UPDATED_AT\" TEXT," + // 6: updated_at
                "\"DOWNLOAD_COMPLETE\" INTEGER NOT NULL ," + // 7: downloadComplete
                "\"WIDTH\" REAL NOT NULL ," + // 8: width
                "\"HEIGHT\" REAL NOT NULL ," + // 9: height
                "\"SCREEN01\" INTEGER NOT NULL ," + // 10: screen01
                "\"SCREEN02\" INTEGER NOT NULL ," + // 11: screen02
                "\"POSITION_BEANS\" TEXT);"); // 12: positionBeans
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"SCENE_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, SceneBean entity) {
        stmt.clearBindings();
 
        String background = entity.getBackground();
        if (background != null) {
            stmt.bindString(1, background);
        }
 
        String created_at = entity.getCreated_at();
        if (created_at != null) {
            stmt.bindString(2, created_at);
        }
 
        String duration = entity.getDuration();
        if (duration != null) {
            stmt.bindString(3, duration);
        }
        stmt.bindLong(4, entity.getId());
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(5, name);
        }
        stmt.bindLong(6, entity.getSerial());
 
        String updated_at = entity.getUpdated_at();
        if (updated_at != null) {
            stmt.bindString(7, updated_at);
        }
        stmt.bindLong(8, entity.getDownloadComplete() ? 1L: 0L);
        stmt.bindDouble(9, entity.getWidth());
        stmt.bindDouble(10, entity.getHeight());
        stmt.bindLong(11, entity.getScreen01());
        stmt.bindLong(12, entity.getScreen02());
 
        List positionBeans = entity.getPositionBeans();
        if (positionBeans != null) {
            stmt.bindString(13, positionBeansConverter.convertToDatabaseValue(positionBeans));
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, SceneBean entity) {
        stmt.clearBindings();
 
        String background = entity.getBackground();
        if (background != null) {
            stmt.bindString(1, background);
        }
 
        String created_at = entity.getCreated_at();
        if (created_at != null) {
            stmt.bindString(2, created_at);
        }
 
        String duration = entity.getDuration();
        if (duration != null) {
            stmt.bindString(3, duration);
        }
        stmt.bindLong(4, entity.getId());
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(5, name);
        }
        stmt.bindLong(6, entity.getSerial());
 
        String updated_at = entity.getUpdated_at();
        if (updated_at != null) {
            stmt.bindString(7, updated_at);
        }
        stmt.bindLong(8, entity.getDownloadComplete() ? 1L: 0L);
        stmt.bindDouble(9, entity.getWidth());
        stmt.bindDouble(10, entity.getHeight());
        stmt.bindLong(11, entity.getScreen01());
        stmt.bindLong(12, entity.getScreen02());
 
        List positionBeans = entity.getPositionBeans();
        if (positionBeans != null) {
            stmt.bindString(13, positionBeansConverter.convertToDatabaseValue(positionBeans));
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.getLong(offset + 3);
    }    

    @Override
    public SceneBean readEntity(Cursor cursor, int offset) {
        SceneBean entity = new SceneBean( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // background
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // created_at
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // duration
            cursor.getLong(offset + 3), // id
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // name
            cursor.getInt(offset + 5), // serial
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // updated_at
            cursor.getShort(offset + 7) != 0, // downloadComplete
            cursor.getFloat(offset + 8), // width
            cursor.getFloat(offset + 9), // height
            cursor.getInt(offset + 10), // screen01
            cursor.getInt(offset + 11), // screen02
            cursor.isNull(offset + 12) ? null : positionBeansConverter.convertToEntityProperty(cursor.getString(offset + 12)) // positionBeans
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, SceneBean entity, int offset) {
        entity.setBackground(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setCreated_at(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setDuration(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setId(cursor.getLong(offset + 3));
        entity.setName(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setSerial(cursor.getInt(offset + 5));
        entity.setUpdated_at(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setDownloadComplete(cursor.getShort(offset + 7) != 0);
        entity.setWidth(cursor.getFloat(offset + 8));
        entity.setHeight(cursor.getFloat(offset + 9));
        entity.setScreen01(cursor.getInt(offset + 10));
        entity.setScreen02(cursor.getInt(offset + 11));
        entity.setPositionBeans(cursor.isNull(offset + 12) ? null : positionBeansConverter.convertToEntityProperty(cursor.getString(offset + 12)));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(SceneBean entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(SceneBean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(SceneBean entity) {
        throw new UnsupportedOperationException("Unsupported for entities with a non-null key");
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
